<template>
  <d2-container>
    
  </d2-container>
</template>
<script>
  import {
    adminLoginUrl
  } from '@/utils/interface';
  export default {
    data() {
      return {
        loginForm: {
          username: '',
          password: ''
        },
        loginRules: {
          username: [{
            required: true,
            message: '请输入用户名',
            trigger: 'blur'
          }],
          password: [{
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      login() {
        this.$refs.loginForm.validate(valid => {
          if (valid) {
            this.$post(adminLoginUrl, {
              username: this.loginForm.username,
              password: this.loginForm.password
            }).then(res => {
              localStorage.setItem('access_token', res.data.access)
              localStorage.setItem('refresh_token', res.data.refresh)

            }).catch(err => {
              console.log(err)
            })
          } else {
            return false
          }
        })
      }
    }
  }
</script>